package com.vic.test.proxy;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class CGLibProxy implements MethodInterceptor{
	
	private static CGLibProxy cgLibProxy = new CGLibProxy();
	
	private CGLibProxy(){}
	
	public  static CGLibProxy  getInstance(){
		return cgLibProxy;
	}

	@SuppressWarnings("unchecked")
	public <T> T getProxy(Class<T> cls){
		return (T) Enhancer.create(cls, this);
	}
	
	public Object intercept(Object obj, Method method, Object[] arg2, MethodProxy proxy) throws Throwable {
		b();
		Object result = proxy.invokeSuper(obj, arg2);
		a();
		return null;
	}
	
	
	public void b(){
		System.out.println("-------------------------");
	}
	public void a(){
		System.out.println("=========================");
	}

}

